package com.hnx.admin.aurora.system.controller;

import com.hnx.admin.aurora.annotation.Log;
import com.hnx.admin.aurora.enums.BusinessType;
import com.hnx.admin.aurora.system.domain.param.menu.form.MenuForm;
import com.hnx.admin.aurora.system.domain.param.menu.query.MenuQuery;
import com.hnx.admin.aurora.system.service.MenuService;
import com.hnx.admin.aurora.utils.UUIDUtil;
import com.hnx.admin.aurora.web.json.ResultJson;
import lombok.RequiredArgsConstructor;
import org.springframework.lang.Nullable;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/*
创建人： 倔强的头发
创建时间：2025/6/21
功能描述:

*/
@RestController
@RequiredArgsConstructor
@RequestMapping("/system/menu")
public class SysMenuController {
    private final MenuService menuService;

    /**
     * 加载对应角色菜单列表树
     */
    @GetMapping(value = "/roleMenuTreeselect/{roleId}")
    public ResultJson roleMenuTreeselect(@PathVariable("roleId") String roleId) {
        return menuService.roleMenuTreeselect(roleId);
    }

    /**
     * 获取菜单下拉树列表
     */
    @GetMapping("/treeselect")
    public ResultJson treeselect() {

        return menuService.selectMenuTreeList();
    }
    /**
     * 获取菜单列表
     */
    @PreAuthorize("@auth.hasPermi('system:menu:list')")
    @GetMapping("/list")
    public ResultJson list(@Nullable MenuQuery menu)
    {
        return  menuService.selectMenuList(menu);
    }
    /**
     * 修改菜单
     */
    @PreAuthorize("@auth.hasPermi('system:menu:edit')")
    @Log(title = "菜单管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public ResultJson edit(@Validated @RequestBody MenuForm menu)
    {
        return menuService.updateMenu(menu);
    }
    /**
     * 新增菜单
     */
    @PreAuthorize("@auth.hasPermi('system:menu:add')")
    @Log(title = "菜单管理", businessType = BusinessType.INSERT)
    @PostMapping
    public ResultJson add(@Validated @RequestBody MenuForm menu)
    {
        menu.setMenuId(UUIDUtil.getUUID());
        return menuService.insertMenu(menu);
    }
    /**
     * 删除菜单
     */
    @PreAuthorize("@auth.hasPermi('system:menu:remove')")
    @Log(title = "菜单管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{menuId}")
    public ResultJson remove(@PathVariable("menuId") String menuId)
    {
        return menuService.deleteMenuById(menuId);
    }
    /**
     * 根据菜单编号获取详细信息
     */
    @PreAuthorize("@auth.hasPermi('system:menu:query')")
    @GetMapping(value = "/{menuId}")
    public ResultJson getInfo(@PathVariable String menuId)
    {
        return menuService.selectMenuById(menuId);
    }

}
